<template>
  <!-- 修改资料 -->
  <div>
    <!-- 内容主题区域 -->
    <el-form
      label-width="110px"
      :model="form"
      label-position="right"
      ref="formRef"
      :rules="formRules"
    >
      <el-row>
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
          <el-form-item label="模块key" prop="模块key">
            <el-input v-model="form.appKey" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
          <el-form-item label="模块名称" prop="appName">
            <el-input v-model="form.appName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
          <el-form-item label="json文件名" prop="fileName">
            <el-input v-model="form.fileName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="button-position">
      <el-button @click="updateVisible">取 消</el-button>
      <el-button type="primary" @click="add(formRef)">确 定</el-button>
    </div>
  </div>
</template>
  
  <script setup>
import { reactive, ref, onMounted } from "vue";
import { ElNotification } from "element-plus";
import { useRouter } from "vue-router";
import { Check, Close, Folder } from "@element-plus/icons-vue";
import Api from "@/api/model/meta";
const emit = defineEmits(["updatetable"]);
const router = useRouter()
// 添加用户数据的对象
const form = ref({});
const configData = ref({});
const props = defineProps({
  paramsData: {
    type: Object,
    defalut: {},
  },
});
onMounted(() => {
  getInit();
});

const getInit = async () => {
  let res = await Api.businessrule.add.post(props.paramsData);
  if (res.code == "200") {
    form.value = res.data;
  }
};
const restAddFormData = () => {
  formRef.value.resetFields();
};

const updateVisible = (val) => {
  emit("updatetable");
};

// 上传
const add = async (formRef) => {
  await formRef.validate((valid, fields) => {
    if (valid) {
      addData();
    }
  });
};

const addData = async () => {
  let params = {
    bean: form.value,
  };
  let res = await Api.businessrule.save.post(params);
  if (res.code == 200) {
    restAddFormData();
    ElNotification.success({
      title: "",
      message: "添加成功！",
      duration: 2000,
    });
    emit("updatetable", true);
    router.push({
      path: "/businessrule",
      query: { fileName: form.value.appName},
    });
  }
};
</script>
  
  <style lang="less" scoped>
</style>
  
  